<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/common/meta.jsp"%>
<link rel="stylesheet" type="text/css" href="${ctx}/css/global.css?v=${v}">
<title>汪星客</title>
</head>
<body>
	<div class="wrap">
	<div class="header_bg">
		<%@ include file="/common/header.jsp"%>
    </div>
    <div class="w">
    	<div class="path box">
    		<form id="search_form" action="${ctx}/search.jsp" method="get">
	            <img src="${ctx}/images/icon.png" />
	            <input id="search_txt" type="text" class="ipt_txt"/>
	            <input name="w" type="hidden"/>
	            <img src="${ctx}/images/icon2.png" />
	            <input id="search_date_begin" name="b" value="${param['b']}" class="easyui-datebox" data-options="pWidth:7" style="width:176px;height:36px;"/>
	            &nbsp;&nbsp;到&nbsp;&nbsp;
	            <input id="search_date_end" name="e" value="${param['e']}" class="easyui-datebox" data-options="pWidth:7" style="width:176px;height:36px;"/>
	            <input type="submit" class="but" value=""/>
	    	</form>
        </div>
    </div>
    <div class="main">
    	<div class="list box">
        	<div class="left">
            	<div class="tit" id="search_info">
	            	<p class="p1">搜索的地区：<span></span></p>
	            	<p class="p2">0 - 0，共<span> 0 </span>个结果</p>
            	</div>
                <div id="search_list_body">
                 
                </div>
                <div class="page">
                	<div class="page_nun">
						
                	</div>
                    <div class="page_r" id="search_list_foot">0 - 0,共<span> 0 </span>个结果</div>
                </div>
            </div>
            <div class="right"><img src="${ctx}/images/ad.jpg" /></div>
        </div>
        <div class="clear"></div>
    </div>
    <div class="footer_bg">
    	<%@ include file="/common/footer.jsp"%>
    </div>
</div>
</body>
<script type="text/javascript">
var word = "${param['w']}";
$(function(){
	$("#search_form").on("submit", function(event) {
		$("input[name='w']").val(encodeURI($("#search_txt").val()));
		//event.preventDefault();
	});
	if($.trim(decodeURI(word)) != "") {
		$("#search_txt").css("color", "#000000").val(decodeURI(word));
	}
	
	$("#search_txt").focus(function(){
		var txt_val = $(this).val();
		if(txt_val == "输入您的位置"){
			$(this).val("").css("color", "#000000");
		}
	}).blur(function(){
		var txt_val = $(this).val();
		if(txt_val == ""){
			$(this).val("输入您的位置").css("color", "#D8CED6");
		}
	});
	//执行查询
	onSearch();
// 	$("#search_date_begin").datebox({onShowPanel:function(){
// 		var thisVal = $(this).datebox("getValue");
// 		filterCalendarDate(thisVal);
// 		$("div.datebox-calendar-inner,div.datebox-button").unbind("click").click(function(){
// 			filterCalendarDate(thisVal);
// 		});
// 	}});
// 	$("#search_date_end").datebox({onShowPanel:function(){
// 		var thisVal = $(this).datebox("getValue");
// 		filterCalendarDate(thisVal);
// 		$("div.datebox-calendar-inner,div.datebox-button").unbind("click").click(function(){
// 			filterCalendarDate(thisVal);
// 		});
// 	},
// 	onHidePanel:function(){
// 		$(this).datebox("panel");
// 	}});
	
	//设置日期控件可选项
// 	function filterCalendarDate(val) {
// 		var minDate = new Date($.now() - 24 * 60 * 60 * 1000);
// 		var maxDate = null;
// 		if($("#search_date_begin").datebox("getValue") != "" && $("#search_date_begin").datebox("getValue") != val) {
// 			minDate = new Date($("#search_date_begin").datebox("getValue"));
// 		}
// 		if($("#search_date_end").datebox("getValue") != "" && $("#search_date_end").datebox("getValue") != val) {
// 			maxDate = new Date($("#search_date_end").datebox("getValue"));
// 		}
// 	 	$("div.calendar-body td.calendar-day").each(function(){
// 			var parts = $(this).attr('abbr').split(',');
// 			var tdDate = new Date(parts[0], parseInt(parts[1])-1, parts[2]);
// 			if((tdDate <= minDate) || (maxDate != null && tdDate > maxDate)) {
// 				$(this).css({"background-color":"#CCCCCC", opacity: 0.3, cursor:"default"}).unbind("click");
// 			}
// 		});
// 	}
});
function onSearch() {
	var submitData = {word:$("#search_txt").val()};
	if($("#search_date_begin").datebox("getValue") != "" && $("#search_date_end").datebox("getValue") != "") {
		submitData["s_dateBegan"] = $("#search_date_begin").datebox("getValue");
		submitData["s_dateEnd"] = $("#search_date_end").datebox("getValue");
	}
	if("${param['p']}" != "") {
		submitData["pageNum"] = "${param['p']}";
	}
	$.post("${ctx}/search/host.do", submitData, function(data){
		setPageTools(data);
		var beganNum = data.rows.length == 0?0:(data.pageNum - 1) * data.pageSize + 1;
		var endNum;
		if(beganNum == 0) {
			endNum = 0;
		} else {
			endNum = (data.rows.length < data.pageSize?beganNum + data.rows.length - 1:beganNum + data.pageSize - 1);
		}
		$("#search_info").html("<p class='p1'>搜索的地区：<span>" + submitData.word + "</span></p><p class='p2'>" + beganNum + " - " + endNum + "，共<span> " + data.total + " </span>个结果</p>");
		$("#search_list_foot").html(beganNum + " - " + endNum + "，共<span> " + data.total + " </span>个结果");
// 		<p class="p1">搜索的地区：<span id="search_info"></span></p><p class="p2">1 - 20，共<span> 729 </span>个结果</p>
		$("#search_list_body").html("");
		$.each(data.rows, function(){
			var $showHref = $("<a></a>").attr({href:"${ctx}/show.jsp?id=" + this.id});
			var imgSrc = "${ctx}/images/user_no_head.jpg";
			if(this.userPhotoPath) {
				imgSrc = "${ctx}/tools/download.do?dir=HEAD&fileName=" + this.userPhotoPath;
			}
			var $imgBox = $("<div class='list_m_img'></div>").append($("<img src='" + imgSrc + "' />").wrap($showHref));
			var $infoTit = $("<div></div>").addClass("infor_tit")
				.append($showHref.clone().append($("<h4>").html(this.hostName)))
				.append($("<p>已获得<span> " + (this.assessNum==undefined?0:this.assessNum) + " </span>份评价</p>"));
			var $infoBox = $("<div></div>").addClass("list_infor")
				.append($infoTit)
				.append("<p class='p3'><span>￥" + this.serverVal + "/</span>晚 <span>" + this.cityName + " " + this.distName + " " + this.hostArea + "</span></p>")
				.append($("<p class='hostDescribe'></p>").html(this.hostDescribe))
				.append($showHref.clone().append($("<span></span>").css("float","right").html("查看详情>>")));
			
			var $host = $("<div></div>").addClass("list_m").append($imgBox).append($infoBox);
			$("#search_list_body").append($host);
			//设置超出文本
			$infoBox.find("p.hostDescribe").overflow();
			
			$imgBox.find(" img").imgAuto(100, 100);
		});
	},"json");
}

function setPageTools(page) {
	//"total":1,"pageCount":1,"next":false,"previous":false,"pageSize":10,"pageNum":1,
	$(".page_nun").html("");
	if(page.previous == true) {
		$(".page_nun").append("<a href='${ctx}/search.jsp?w=" + encodeURI(word) + "&p=" + (page.pageNum - 1) + "'><img src='${ctx}/images/page_pre.png' /></a>");
	}
	for(var i=1;i<3&&page.pageNum>=5;i++) {
		$(".page_nun").append("<a href='${ctx}/search.jsp?w=" + encodeURI(word) + "&p=" + i + "'>" +i+ "</a>");
	}
	for(var i=page.pageNum-2;i<page.pageNum&&i>2;i++) {
		$(".page_nun").append("<a href='${ctx}/search.jsp?w=" + encodeURI(word) + "&p=" + i + "'>" +i+ "</a>");
	}
	$(".page_nun").append("<a href='javascript:void(0)' class='onpage'>" +page.pageNum+ "</a>");
	for(var i=page.pageNum+1;i<page.pageNum+2&&i<=(page.pageCount-2);i++) {
		$(".page_nun").append("<a href='${ctx}/search.jsp?w=" + encodeURI(word) + "&p=" + i + "'>" +i+ "</a>");
	}
	for(var i=page.pageCount-2;i<=page.pageCount&&page.pageNum<i;i++) {
		$(".page_nun").append("<a href='${ctx}/search.jsp?w=" + encodeURI(word) + "&p=" + i + "'>" +i+ "</a>");
	}
	if(page.next == true) {
		$(".page_nun").append("<a href='${ctx}/search.jsp?w=" + encodeURI(word) + "&p=" + (page.pageNum + 1) + "'><img src='${ctx}/images/page_next.png' /></a>");
	}
}
</script>
</html>